package com.example.mobile2121606109ycg0407;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivityTip1 extends AppCompatActivity {

    private EditText edtTxtMainNumA;
    private EditText edtTxtMainNumB;
    private TextView tvMainResult;
    private Button btnMainResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_tip1);
        initView();

        btnMainResult.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //获取A、B
                int a = Integer.parseInt(edtTxtMainNumA.getText().toString());
                int b = Integer.parseInt(edtTxtMainNumB.getText().toString());
                //计算整数和
                int sum = a+b;
                //输出结果
                tvMainResult.setText(String.valueOf(sum));
            }
        });
    }

    private void initView() {
        edtTxtMainNumA = (EditText) findViewById(R.id.edtTxtMainNumA);
        edtTxtMainNumB = (EditText) findViewById(R.id.edtTxtMainNumB);
        tvMainResult = (TextView) findViewById(R.id.tvMainResult);
        btnMainResult = (Button) findViewById(R.id.btnMainResult);
    }
}